package com.huxin.servelt;

import com.alibaba.fastjson.JSON;
import com.huxin.pojo.BookHisInfo;
import com.huxin.pojo.ConditionalQueryDTO;
import com.huxin.pojo.PageBean;
import com.huxin.service.Userservice;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 *查询用户借阅历史
 */
@WebServlet("/selectall1")
public class SLAbrohisServlet1 extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //获取请求方法
        request.setCharacterEncoding("utf-8");
        //处理响应乱码
        response.setContentType("text/json;charset=utf-8");
        Userservice service = new Userservice();
        String s = request.getReader().readLine();
        int page=1;//开始页
        int size=10;//每页显示十条数据
//        if(null==conditionalQueryDTO.getPage()){
//            conditionalQueryDTO.setPage(page);
//        }
//        if(null!=conditionalQueryDTO.getSize()){
//            conditionalQueryDTO.setSize(size);
//        }
        PageBean<BookHisInfo> bean=null;
        //拿到该用户的id
        HttpSession session = request.getSession();
        // todo
        Integer aid = (Integer) session.getAttribute("userId");
        bean=service.findAllById(aid,page,size);
        //分页查询
        String str= JSON.toJSONString(bean);

        response.getWriter().write(str);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
